home *** CD-ROM | disk | FTP | other *** search
- Path: news.ems.psu.edu!usenet
- From: mahesh@cerse.psu.edu (Mahesh Venkitachalam)
- Newsgroups: comp.lang.c++
- Subject: Need help with overloading "<<"
- Date: 21 Jan 1996 22:32:00 GMT
- Organization: PSU - Earth and Mineral Sciences
- Message-ID: <4duet0$ju9@wegener.ems.psu.edu>
- Reply-To: mahesh@cerse.psu.edu
- NNTP-Posting-Host: eagle.cerse.psu.edu
-
- Hi !
-
- I was trying to overload the "<<" operator for a Complex class,
- without much sucess. Could someone please help me out ?
-
- In the main program, when I do
-
- cout << a << endl ; ( here a is defined as Complex a(1.0, 1.0) ;)
-
- the compiler gives the following error :
-
- "prog2.C", line 11.21: 1540-070: (S) Call does not match any argument list
-
- for "ostream::operator<<".
-
-
- The overloading function is :
-
- ostream& operator<<(ostream& s, Complex& z)
- {
- s << z.real() << " + " << z.img() <<"i" << endl;
- return s;
- }
-
-
- and the class definition is :
-
- // complex1.h
-
- class Complex
- {
- private:
-
- double real_;
- double img_;
-
- public:
-
- Complex(); // Constuctors
- Complex(double real, double img);
-
- Complex operator+ (Complex& z); // operations
-
- double real() {return real_;}
- double img() {return img_ ;}
-
- void cprint();
-
- ~Complex() ; // destructor
-
- } ;
-
-
- I have been stuck with this for some time now...
-
-
- Thanks a lot
-
- Mahesh
-
-
-
-